﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.IO;
using MySql.Data.MySqlClient;

namespace VSDBM.Code
{
    public class Connection
    {
        private static String Servidor;
        private static Int32 Porta;
        private static String User;
        private static String Pass;
        private static MySqlConnection connection;
		

		public static MySqlConnection getConnection()
        {
            
         
           
            if (connection == null)
            {
                List<string> parametros = new List<string>();


                DataBaseConfig dbconf = new DataBaseConfig();
                dbconf = dbconf.getConfig();
                Servidor = dbconf.servidor;
                Porta = Convert.ToInt32(dbconf.porta);
                User = dbconf.user;
                Pass = dbconf.senha;
                connection = new MySqlConnection("SERVER=" + Servidor +"; DATABASE=vsdbm; UID="+User+"; PASSWORD="+Pass+";");
            }

            if (connection.State == ConnectionState.Closed)
            {
                connection.Open();
            }
           
            return connection;
        }
        public static MySqlConnection getNewConnection()
        {


            
           
                List<string> parametros = new List<string>();


                DataBaseConfig dbconf = new DataBaseConfig();
                dbconf = dbconf.getConfig();
                Servidor = dbconf.servidor;
                Porta = Convert.ToInt32(dbconf.porta);
                User = dbconf.user;
                Pass = dbconf.senha;
               MySqlConnection newconnection = new MySqlConnection("SERVER=" + Servidor + "; DATABASE=vsdbm; UID=" + User + "; PASSWORD=" + Pass + ";");
            

            if (newconnection.State == ConnectionState.Closed)
            {
                newconnection.Open();
            }

            return newconnection;
        }





       
    }
}